package pl.controller;

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.reading.CaptchaReader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;

public class CaptchaTestMain {

	protected final Log log = LogFactory.getLog(getClass());
	
	public CaptchaTestMain() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		CaptchaTestMain main = new CaptchaTestMain();
		main.go();
	}

	private void go() {
		try {
			log.debug("go start");
			CaptchaReader cr = new CaptchaReader();
			FileOutputStream fos = new FileOutputStream("/tmp/captcha.jpeg");
			cr.setOutputStream(fos);
			
			SourceResolver resolver = null;
			Parameters parameters = new Parameters();
			parameters.setParameter("width", "300");
			parameters.setParameter("height", "200");
			cr.setup(resolver, null, "axw10", parameters);
			cr.generate();
			fos.flush();
			fos.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
